<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ page import="com.easyui.common.UserLogin, com.easyui.common.SelProject, com.easyui.bean.Project" %>
<%@ page import="java.util.List, java.util.Map" %>

<%
	int pno = Integer.parseInt(request.getParameter("pno"));

	List<Project> plist = null;
	plist = new SelProject().getProjectDetail(pno);//获得项目详细
	if (plist != null && plist.size() > 0) {
		Project p = (Project) plist.get(0);
		String pname = p.getPname();
		String progress = p.getProgress();
		String pr = "";
		if(progress.equals("1")) {
			pr = "已完成";
		} else {
			pr = "进行中";
		}
		
		List<Map> memberList = p.getMemberList();
		String memberString = "";
		if(memberList != null && memberList.size() > 0) {
			for (int i = 0; i < memberList.size(); i++) {
				Map<String, String> map = memberList.get(i);
				String sname = map.get("sname");
				if (i != 0) {
					memberString += ",&nbsp;&nbsp;" + sname;
				} else {
					memberString += sname;
				}
			}
		}
		
%>

<script type="text/javascript" charset="UTF-8">
	var modifyProjectForm;
	var modifyTakerCombogrid;
	var sexData = [{
		"id":"male",
		"text":"男"
	},{
		"id":"female",
		"text":"女",
	}];
	
	$(function() {
		modifyProjectForm = $('#modifyProjectForm').form({
			url:'servlet/GetModifyServlet',
			onSubmit: function(){  
				var ncont =  $.trim($("#pdetail").val()) != "",
				 	isValid = $(this).form('validate');
					var result =isValid  && ncont;
					if(!result) {
						$.messager.alert('请填写完整', '请填写完整！', 'error');
						return false;
					} 
   				 },
			success: function(msg){
				if(msg == 'ok') {
					$('#modifyProjectDialog').dialog('close');
					var title = '项目详情_<%= pname %>';
					projectDetailDialog = $('#projectDetailDialog').dialog({
						title:title,
						modal:true,
						collapsible:false,
						showHeader:false,
						width:650,
						height:550,
						href:'teacher/projectDetail.jsp?pno=' + <%= pno %> + '&pname=<%= pname %>'
					});
					$.messager.show({
						title:'提示',
						msg:'修改项目信息成功'
					});
					
					projectDetailDialog.dialog('open');
				} else {
					$.messager.alert('操作失败','修改项目信息失败！','error');
					console.info('error');
				}
			}
	});
		modifyTakerCombogrid = $('#modifyTakerCombogrid').combogrid({   
			url:'servlet/GetAddStudent?pno=' + <%= pno %>,
			fitColumns:true,
			mode:'remote',
			panelWidth:450,
			nowrap:false,
			idField:'sno',
			textField: 'sname',
			pagination:false,
			editable:false,
			multiple:true,
			fit:true,
			border:false,
			sortName:'sno',
			sortOrder:'desc',
			columns:[[{
				field:'cut',
				checkbox:true
			},{
				title:'学号',
				field:'sno',
				width:100,
				sortable:true
			},{
				title:'姓名',
				field:'sname',
				width:100,
				sortable:true
			},{
				title:'性别',
				field:'sex',
				width:100,
				sortable:true,
				formatter:function(value,rowData,rowIndex){
					 for(var i=0; i<sexData.length; i++){  
			                if (sexData[i].id == value) {
			                	return sexData[i].text;  
			                }
		            }  
				}
			},{
				title:'分工',
				field:'stype',
				width:100
			}]]
		});
		
	});
	
	cancelModify = function() {
		$('#modifyProjectDialog').dialog('close');
	}
	
	
</script>

<div style="width:600px;margin:0 auto;">
		<form id="modifyProjectForm" style="margin:20px auto;" method="post" >
		<input type="hidden" name="pno" id="pno" value="<%= p.getPno() %>" />
				<table style="margin:auto;border:1px #09F solid;">
					<tr style="width:70px;">
						<td style="width:100px;text-align:left"><b>项目名称</b></td>
						<td><input type="text" name="pname" id="pname" value="<%= p.getPname() %>" class="easyui-validatebox" style="width:300px;" required="true"/></td>
					</tr>
					<tr style="width:70px;">
						<td style="width:100px;text-align:left"><b>已有人员</b></td>
						<td><%= memberString %></td>
					</tr>
					<tr style="width:70px;">
						<td style="width:100px;text-align:left"><b>增加人员</b></td>
						<td><input type="text" name="addtaker" id="modifyTakerCombogrid" style="width:300px;" class="easyui-combogrid" />
						</td>
					</tr>
					<tr style="width:70px;">
						<td style="width:100px;text-align:left"><b>截止时间</b></td>
						<td><input type="text" name="etime" id="etime" value="<%= p.getEtime() %>" style="width:200px;" class="easyui-datetimebox" required="true" editable="false"/></td>
					</tr>
					<tr>
						<td style="width:100px;text-align:left;vertical-align:top;"><b>项目描述</b></td>
						<td><textarea name="pdetail" id="pdetail" rows="10" cols="70" ><%= p.getPcont() %></textarea></td>
					</tr>
					<!-- <tr style="width:70px;" class="addfile">
						<td style="width:60px;text-align:left"><b>添加附件</b></td>
						<td><input type="file" name="attach" id="attach"/></td> 
					</tr> -->
					<tr style="width:70px;display:none;" id="hiddenbox"> <!--往后台传送数据的容器-->	
					</tr>
					<tr>
						<td style="width:100px;text-align:left"><b>总体进度</b></td>
						<td><%= pr %></td>
					</tr>
					<% 
						if(memberList != null && memberList.size() > 0) {
							for (int m = 0; m < memberList.size(); m++) {
								Map<String, String> map = memberList.get(m);
								String sname = map.get("sname");
								String stage = map.get("stage");
								String sno = map.get("sno");
					%>
					<tr>
						<td style="width:100px;text-align:left"><%= sname %></td>
						<td><input type="text" id="stage" name="stage" class="easyui-combobox" style="width:120px;" data-options="   
							        data:[{
							        	'id':'<%= sno %>,todo',
										'text':'待接受',
									},{
										'id':'<%= sno %>,doing',
										'text':'进行中',
									},{
										'id':'<%= sno %>,done',
										'text':'已完成'
									}],
									panelHeight:150,
									editable:false,
									valueField:'id',
									textField:'text',
									onLoadSuccess: function () { 
										var s = '<%= stage %>';
									    var datas = $(this).combobox('getData');
										var index = -1;
										if(s == 'todo') {
											index = 0;
										} else if(s == 'doing'){
											index = 1;
										} else {
											index = 2;
										}
									    $(this).combobox('select', datas[index].id);
						            }" />  
						</td>
					</tr>
					<%
							}
						}
					%>
					<tr>
						<td colspan="2" align="right">
							<a href="javascript:void(0);" class="easyui-linkbutton"  pain="false" onclick="modifyProjectForm.submit();" >确定</a>
							<a href="javascript:void(0);" class="easyui-linkbutton"  pain="false" onclick="cancelModify();" >取消</a>
						</td>
					</tr>
					
				</table>
			</form>
</div>
<%
	}
%>
<script type="text/javascript" src="js/addFile.js" charset="UTF-8"></script>  